Completed
Push — master ( 158ed8...34f194 )
by Alejandro
04:53 queued 02:19
created

provideServices.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 35
nc 1
nop 2
dl 0
loc 54
rs 9.0399
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import { connect as reduxConnect } from 'react-redux';
2
import { assoc } from 'ramda';
3
import ShortUrls from '../ShortUrls';
4
import SearchBar from '../SearchBar';
5
import ShortUrlsList from '../ShortUrlsList';
6
import ShortUrlsRow from '../helpers/ShortUrlsRow';
7
import ShortUrlsRowMenu from '../helpers/ShortUrlsRowMenu';
8
import CreateShortUrl from '../CreateShortUrl';
9
import DeleteShortUrlModal from '../helpers/DeleteShortUrlModal';
10
import EditTagsModal from '../helpers/EditTagsModal';
11
import CreateShortUrlResult from '../helpers/CreateShortUrlResult';
12
import { listShortUrls } from '../reducers/shortUrlsList';
13
import { createShortUrl, resetCreateShortUrl } from '../reducers/shortUrlCreation';
14
import { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } from '../reducers/shortUrlDeletion';
15
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../reducers/shortUrlTags';
16
import { resetShortUrlParams } from '../reducers/shortUrlsListParams';
17
18
const provideServices = (bottle, connect) => {
19
  // Components
20
  bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList');
21
  bottle.decorator('ShortUrls', reduxConnect(
22
    (state) => assoc('shortUrlsList', state.shortUrlsList.shortUrls, state.shortUrlsList)
23
  ));
24
25
  bottle.serviceFactory('SearchBar', SearchBar, 'ColorGenerator');
26
  bottle.decorator('SearchBar', connect([ 'shortUrlsListParams' ], [ 'listShortUrls' ]));
27
28
  bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
29
  bottle.decorator('ShortUrlsList', connect(
30
    [ 'selectedServer', 'shortUrlsListParams' ],
31
    [ 'listShortUrls', 'resetShortUrlParams' ]
32
  ));
33
34
  bottle.serviceFactory('ShortUrlsRow', ShortUrlsRow, 'ShortUrlsRowMenu', 'ColorGenerator', 'stateFlagTimeout');
35
36
  bottle.serviceFactory('ShortUrlsRowMenu', ShortUrlsRowMenu, 'DeleteShortUrlModal', 'EditTagsModal');
37
  bottle.serviceFactory('CreateShortUrlResult', CreateShortUrlResult, 'stateFlagTimeout');
38
39
  bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector', 'CreateShortUrlResult');
40
  bottle.decorator(
41
    'CreateShortUrl',
42
    connect([ 'shortUrlCreationResult' ], [ 'createShortUrl', 'resetCreateShortUrl' ])
43
  );
44
45
  bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal);
46
  bottle.decorator('DeleteShortUrlModal', connect(
47
    [ 'shortUrlDeletion' ],
48
    [ 'deleteShortUrl', 'resetDeleteShortUrl', 'shortUrlDeleted' ]
49
  ));
50
51
  bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector');
52
  bottle.decorator('EditTagsModal', connect(
53
    [ 'shortUrlTags' ],
54
    [ 'editShortUrlTags', 'resetShortUrlsTags', 'shortUrlTagsEdited' ]
55
  ));
56
57
  // Actions
58
  bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'buildShlinkApiClient');
59
  bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags);
60
  bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited);
61
62
  bottle.serviceFactory('listShortUrls', listShortUrls, 'buildShlinkApiClient');
63
  bottle.serviceFactory('resetShortUrlParams', () => resetShortUrlParams);
64
65
  bottle.serviceFactory('createShortUrl', createShortUrl, 'buildShlinkApiClient');
66
  bottle.serviceFactory('resetCreateShortUrl', () => resetCreateShortUrl);
67
68
  bottle.serviceFactory('deleteShortUrl', deleteShortUrl, 'buildShlinkApiClient');
69
  bottle.serviceFactory('resetDeleteShortUrl', () => resetDeleteShortUrl);
70
  bottle.serviceFactory('shortUrlDeleted', () => shortUrlDeleted);
71
};
72
73
export default provideServices;
74